<%@ page language="java" import="java.util.*, com.rmt.www.vo.*" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
 
	<link  rel="stylesheet" type="text/css" href="css/navigator.css" />
	<link href="css/Site.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" language="javascript" src="js/jquery-1.7.1.js"></script>
	<script src="js/jquery-ui-1.8.18.custom.min.js"></script>
		<link href="css/jquery-ui-1.8.18.custom.css" rel="stylesheet"
			type="text/css" />
	<script>
		$(function(){
			$( "input:submit, :button").button();
			
			$('#addProjectForm').hide();
			$('#editProjectForm').hide();
			$('input[value="add"]').click(function(){
				 $('#addProjectForm').toggle();
			});
			
			$('input[value="delete"]').click(function(){
				var i=$('input:checked').length;
			 	var url='deleteProject?';
				//var pid=new Array();
				if(i<1){
					alert('please choose at least one project!');
				}else{
				
					$('input:checked').each(function(){
					 	url=url+'pid='+$(this).attr('value')+'&';
					});
					url=url.slice(0,-1);
					//后台删除数据
					//pid=$.param(pid,true);
					$.ajax({
					  url: url,
					  cache:false,
					  success: function(returnData, textStatus) {
					  	  $('input:checked').each(function(){					  	  		
					 			$(this).parent().parent().hide();
					 			$(this).attr('checked',false);
							});
						},
					    error: function(xhr, textStatus, errorThrown) {
					      	alert('fail');
					    }
					});
				}
				
			});
			
			$('input[value="detail"]').click(function(){
				var i=$('input:checked').length;
				if(i!=1){
					alert('please choose exactly one project!');
				}else{
					//window.location.href="admin/detail.jsp";
					var pid;
					var url='detailAction?pid=';
					$('input:checked').each(function(){
						pid=$(this).attr('value');
						url+=pid;
					});
					window.open(url,"_self");
				}
			});
			
			$('input[value="trace"]').click(function(){
				var i=$('input:checked').length;
				if(i!=1){
					alert('please choose exactly one project!');
				}else{
					var pid;
					var url='trace?pid=';
					$('input:checked').each(function(){
						pid=$(this).attr('value');
						url+=pid;
					});
					window.open(url,"_self");
				}
			});
			
			
			$('input[value="create baseline"]').click(function(){
				var i=$('input:checked').length;
				if(i!=1){
					alert('please choose exactly one project!');
					return;
				}
				if (confirm("Are you sure to create the baseline of the project?")) {
					//window.location.href="admin/detail.jsp";
					var pid;
					var url='createBaselineAction?pid=';
					$('input:checked').each(function(){
						pid=$(this).attr('value');
						url+=pid;
					});
					window.open(url,"_self");
				}
			});
			
			$('input[value="changeControl"]').click(function(){
				var i=$('input:checked').length;
				if(i!=1){
					alert('please choose exactly one project!');
				}else{
					//window.location.href="admin/detail.jsp";
					var pid;
					var url='changeControlAction?pid=';
					$('input:checked').each(function(){
						pid=$(this).attr('value');
						url+=pid;
					});
					window.open(url, "_self");
				}
			});
			
			$('input[value="report"]').click(function() {
				var len = $('input:checked').length;
				if (len != 1) {
					alert("please choose exactly one project")
					$('input.checked').each(function() {
						$(this).attr("checked", false);
					});
				} else {
					var url = 'report?pid=';
					$('input:checked').each(function() {
						url += $(this).attr('value');  
					});
					window.open(url, "_self");
				}
			});
			
			$('input[value="edit"]').click(function(){
				
				var i = $('input:checked').length;
				if (i != 1) { //选择且只能选择一个project
					alert("please choose only one project to edit!");
					//恢复所有用户都不勾选状态
				    $("input:checked").each(function(){	
				    	$(this).attr("checked", "false");
				    });
				} else {
					//显示编辑用户表单界面
				    $('#editProjectForm').toggle();
					$('#addProjectForm').hide();
					var pid = $("input:checked").attr("value");
				    var row = $("input:checked").parent().parent();
				    var projectname = row.children().eq(1).html().trim();
				    var description = row.children().eq(2).html().trim();
				    $("#edittitle").val(projectname);
				    $("#editdesc").val(description);
				    $("#editpid").val(pid);
<%--				    var uid = $("input:checked").attr("value");--%>
<%--				    var row = $("input:checked").parent().parent();--%>
<%--				    //获得用户类型--%>
<%--				    var type = row.children().eq(1).html().trim(); --%>
<%--				    var typeSelect = "#editUserType option[value=" + type + "]";--%>
<%--				    //设置编辑表单中默认填充数据为用户当前信息--%>
<%--				    $(typeSelect).attr("selected", "selected");--%>
<%--				    var name = row.children().eq(2).html().trim();--%>
<%--				    $("#editUserName").val(name);--%>
<%--				    var password = row.children().eq(3).html().trim();--%>
<%--				    $("#editUserPassword").val(password);--%>
<%--				    $("#editUserId").val(uid);--%>
				    $("input:checked").each(function(){
                        $(this).attr("checked", "false");
                    });
				}
			});
		});
	</script>
	
	<style type="text/css"> 
/* CSS Document */ 

a { 
color: #c75f3e; 
} 

#mytable {  
padding: 0; 
margin: 0; 
} 

caption { 
padding: 0 0 5px 0; 
width: 700px; 
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
text-align: right; 
} 

#mytable th { 
font: bold 14px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
color: #4f6b72; 
border-right: 1px solid #C1DAD7; 
border-bottom: 1px solid #C1DAD7; 
border-top: 1px solid #C1DAD7; 
letter-spacing: 2px; 
text-transform: uppercase; 
text-align: left; 
padding: 6px 6px 6px 12px; 
background: #CAE8EA  no-repeat; 
} 
 
#mytable th.nobg { 
border-top: 0; 
border-left: 0; 
border-right: 1px solid #C1DAD7; 
background: none; 
} 

#mytable td { 
border-right: 1px solid #C1DAD7; 
border-bottom: 1px solid #C1DAD7; 
background: #fff; 
font-size:13px; 
padding: 6px 6px 6px 12px; 
color: #4f6b72; 
} 
/*power by www.winshell.cn*/ 

#mytable td.alt { 
background: #F5FAFA; 
color: #797268; 
} 

#mytable th.spec { 
border-left: 1px solid #C1DAD7; 
border-top: 0; 
background: #fff no-repeat; 
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
} 

#mytable th.specalt { 
border-left: 1px solid #C1DAD7; 
border-top: 0; 
background: #f5fafa no-repeat; 
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
color: #797268; 
} 
</style> 
  </head>
  
  <body>
  <div class='page' id='wrap'>
	<div id="header" style='background-color: #5c87b2'>
            <div id="title">
                <h1>&nbsp;&nbsp;RMT Service for administrator</h1>
            </div>
              
            <div id="logindisplay">
                welcome <%=((User)session.getAttribute("currentUser")).getName()%>,  <a href='../RMT'>logout</a>
            </div> 
            <br/>
            <div id="menucontainer">
            
                <ul id="menu">     
                	<li><a href="adminHomeAction">Home</a></li>         
                    <li><a href='getProjectsForAdmin'>Projects</a></li>
                    <li><a href='accountManageAction?manageTarget=account'>Users</a></li>
                </ul>
            
            </div>
        </div>
   <div id='main'>
	<h2>Manage Projects</h2>
	<center>
		<table border="1" id="mytable" align='center'>
		<tr>
			<th>
				choose
			</th>
			<th>
				project name
			</th>
			<th>
				description
			</th>
			<th>
				created time
			</th>
			<th>
				created baseline?
			</th>
		</tr>
		<s:iterator value="projectList" id="list" status="st">
		<tr>
			<td>
				<input  type="checkbox" value='<s:property value="#list.pid" />' />
			</td>
			<td>
				<s:property value="#list.title" /> 
			</td>
			<td>
				<s:property value="#list.description" /> 
			</td>
			<td>
				<s:property value="#list.time" /> 
			</td>
			<td>
				<s:property value="#list.isbaselinecreated"/>
			</td>
		</tr>
		</s:iterator>
	</table>
	
	
	<br/>
	<tr>
		<td><input type="button" value='add' /></td>
		<td><input type='button' value='edit'/></td>
		<td><input type="button" value='delete' /></td>
		<td><input type="button" value="create baseline"/></td>
		<td><input type="button" value='detail' /></td>
		<td><input type="button" value='trace' /></td>
		<td><input type="button" value='changeControl' /></td>
		<td><input type="button" value="report"/></td>
	</tr>
	
	<form id='addProjectForm' action='addProject' method='post'>
		<table>
			<tr>
				<td>
					title
				</td>
				<td>
					<input type='text' name='title' style="width: 823"/>
				</td>
			</tr>
			<tr>
				<td>
					description
				</td>
				<td>
					<textarea rows="10" cols="100" name='description'></textarea>
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<input type='submit' value='submit' />
				</td>
			</tr>
		</table>
	</form>
	 <form id='editProjectForm' action='editProject' method='post'>
	    <table>
	    		<tr style="display:none;">
            <td><input type='text' name='pid' id="editpid"/></td>
        	</tr>
				<tr>
					<td>
						title
					</td>
					<td>
						<input type='text' name='title' style="width: 823" id='edittitle'/>
					</td>
				</tr>
				<tr>
					<td>
						description
					</td>
					<td>
						<textarea rows="10" cols="100" name='description' id='editdesc'></textarea>
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<input type='submit' value='submit' />
					</td>
				</tr>
			</table>
    </form>
	</center>
	</div>
	 <div class="push"></div>
  	<div id="footer" style="background-color:#5c87b2;">
  	  <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:hidden;background-color:#5c87b2;">							
		<tbody style="border:hidden">
			<tr style="border: hidden">	
				<td width="160" style="border: hidden">&nbsp;</td>											   		<td>									
				<table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:hidden;">	
					<tbody style="border: hidden">
						<tr style="border: hidden">
							<td height="20px"><font color='#ffffff'>©2012 Copyright NJU SEI RMT team</font></td>										
						</tr>										
						<tr style="border: hidden">											
							<td height="20px"><font color='#ffffff'>2012 graduation project: requirement management tool</font></td>	
						</tr>										
						<tr style="border: hidden">					
							<td height="20px"><font color='#ffffff'>project homepage：http://code.google.com/p/rmt-ss/</font></td>		
						</tr>									
					</tbody>
				</table>								
				</td>							
			</tr>						
		</tbody>
	</table>	
  	</div>
	
    </div>
    
  </body>
</html>
